<template>
  <div
    :style="{
      paddingBottom: tempData.paddingBottom + 'px',
      paddingLeft: tempData.paddingTwice + 'px',
      paddingRight: tempData.paddingTwice + 'px',
      paddingTop: tempData.paddingTop + 'px',
      boxSizing: 'border-box',
    }"
  >
    <div
      class="notice_content"
      :style="
        tempData.showType == 1 || tempData.showType == null
          ? {
              borderTopLeftRadius: tempData.radiusNumTop + 'px',
              borderTopRightRadius: tempData.radiusNumTop + 'px',
              borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
              borderBottomRightRadius: tempData.radiusNumBottom + 'px',
              background: tempData.boxBg
                ? tempData.boxBg
                : 'linear-gradient(145deg,#3c9cff 80%,#9acafc)',
            }
          : {
              borderTopLeftRadius: tempData.radiusNumTop + 'px',
              borderTopRightRadius: tempData.radiusNumTop + 'px',
              borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
              borderBottomRightRadius: tempData.radiusNumBottom + 'px',
              backgroundImage: 'url(' + tempData.bgImage + ')',
              backgroundSize: '100% 100%',
            }
      "
    >
      <div class="iconBox">
        <icon-sound-fill v-if="tempData.iconType == 'icon'" class="noticeicon" />
        <p class="texts" v-if="tempData.iconType == 'text'">公&nbsp;告</p>
      </div>
      <div class="scrolling-text">
        <div
          class="scrolling-text-content"
          :style="{ color: tempData.textColor }"
          ref="scrollingTextContent"
        >
          {{ tempData.noticeText }}
        </div>
      </div>
      <div class="moreBtn"> 查看更多 </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { ref, onMounted, watch } from 'vue'

  const props = defineProps({
    // 选中的当前组件参数
    compObj: {
      type: Object,
      default: () => {
        return {}
      },
    },
  })
  console.log(props)
  const tempData: any = ref({})
  const steps = ref('3s')
  watch(
    () => props.compObj,
    (newVal, oldVal) => {
      tempData.value = JSON.parse(JSON.stringify(newVal))
      steps.value = tempData.value.step + 's'
    },
    { immediate: true, deep: true }
  )
  const scrollingTextContent: any = ref(null)
  onMounted(() => {
    scrollingTextContent.value.animate(
      { transform: 'translateX(-100%)' },
      { easing: 'linear', direction: 'normal' }
    )
  })
</script>

<style lang="less" scoped>
  .notice_content {
    width: 100%;
    padding: 4px 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .iconBox {
      margin-right: 10px;
      display: flex;
      align-items: center;
      .texts {
        font-size: 13px;
        color: #fff;
      }
      .noticeicon {
        font-size: 16px;
        color: #fff;
      }
    }
    .scrolling-text {
      overflow: hidden;
      white-space: nowrap;
      flex-grow: 1;
      color: #fff;
      .scrolling-text-content {
        width: 100%;
        display: inline-block;
        animation: scroll v-bind(steps) linear infinite normal;
      }
    }

    .moreBtn {
      border: 1px solid #fff;
      color: #fff;
      font-size: 12px;
      line-height: 16px;
      transform: scale(0.8);
      text-align: center;
      padding: 2px 6px;
      border-radius: 5px;
    }
  }

  @keyframes scroll {
    0% {
      transform: translateX(100%);
    }
    100% {
      transform: translateX(-100%);
      display: none;
    }
  }
</style>
